﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using NAudio.Wave;

namespace MidiPlayer
{
    [Serializable]
    public class PlaybackSettingsDto : ISerializable
    {

        public enum Outputs
        {
            DirectSound = 0,
            Asio = 1
        }


        public int Latency;
        public Outputs Output;
        public String AsioDriverName;


        public PlaybackSettingsDto()
        {
            Latency = 40;
            Output = Outputs.DirectSound;
            AsioDriverName = String.Empty;
        }

        public PlaybackSettingsDto(SerializationInfo info, StreamingContext ctxt)
        {
            Latency = (int)info.GetValue("Latency", typeof(int));
            Output = (Outputs)info.GetValue("Output", typeof(Outputs));
            AsioDriverName = (string)info.GetValue("AsioDriver", typeof(string));
            
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Latency", this.Latency);
            info.AddValue("Output", this.Output);
            info.AddValue("AsioDriver", this.AsioDriverName);

        }

        public String GetDisplaySettings()
        {
            string ret;
            if(Output == Outputs.DirectSound )
            {
                ret = "DirectSound";
            }
            else
            {
                ret = "ASIO";
                if(!String.IsNullOrEmpty(AsioDriverName))
                {
                    ret += " (" + AsioDriverName + ")";
                }
            }


            return ret;
        }

        // TODO: Move to model
        public void Validate()
        {
            if (Output == Outputs.Asio && !AsioOut.isSupported())
                throw new ArgumentException("ASIO is selected but not supported");


        }

    }
}
